package cn.zwx.base.utils;

import lombok.Data;

import java.util.List;

/**
 * @author zhangwenxue
 */
@Data
public class PageUtil<T> {

    private Integer total;

    private Integer page;

    private Integer size;

    private Integer current;

    private Boolean hasNextPage;

    private Integer prev;

    private Integer next;

    private List<T> records;


    public PageUtil(Integer pageSize, Integer currentPage, Integer totalCount, List<T> records) {
       int totalPage = totalCount%pageSize == 0 ? totalCount/pageSize : totalCount/pageSize+1;
       totalPage = Math.max(totalPage, 1);
       int nextPage = Math.min(currentPage+1,totalPage);
       int pervPage = Math.max(currentPage-1,1);
       this.current = currentPage;
       this.total = totalCount;
       this.prev = pervPage;
       this.next = nextPage;
       this.records = records;
       this.size = pageSize;
       this.hasNextPage = currentPage.compareTo(totalPage)<0;
       this.page = totalPage;
    }
}
